﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Data;

public partial class Admin_Add_news : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            cldCreatdate.SelectedDate = DateTime.Today;

            
        }
        if (Convert.ToString(Session["Dangnhap"]) == "")
            Response.Redirect("~/Admin/Login.aspx");

        else
            Response.Write("Xin chào " + Convert.ToString(Session["Dangnhap"]));
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection
        (ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        string strInsert2 =
        "INSERT INTO tblNews(newsTitle,newsContent,published,creatorld,createdDate)VALUES";
        strInsert2 += "(@newtit,@newcon,@pub,@creatorid,@creatdate)";
        //,lastEditedUserId,lastEditedDate,@lasedituser,@lasteditdate
        SqlCommand sqlCmd = new SqlCommand(strInsert2, conn);
        sqlCmd.Parameters.AddWithValue("@newtit", txtTitle.Text);
        sqlCmd.Parameters.AddWithValue("@newcon", FCKeditor1.Value);
        sqlCmd.Parameters.AddWithValue("@pub", ddlPublish.SelectedIndex);
        sqlCmd.Parameters.AddWithValue("@creatorid", ddlCreatorID.SelectedIndex);
        sqlCmd.Parameters.AddWithValue("@creatdate", cldCreatdate.SelectedDate);
        //sqlCmd.Parameters.AddWithValue("@lasedituser", ddlEditUser.SelectedIndex);
        //sqlCmd.Parameters.AddWithValue("@lasteditdate", cldLastedit.SelectedDate);
        conn.Open();
        sqlCmd.ExecuteNonQuery();
        conn.Close();
        lblMsg.Text = " Add news successfully ";
    }
}
